#include <stdio.h>

void Swap(int* p1, int* p2)
{
	int tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}

void QuickSort_Point(int* a, int left, int right)
{
	if (left >= right)
	{
		return;
	}

	int keyi = left;
	int prev = left, cur = prev + 1;
	while (cur <= right)
	{
		if (a[cur] < a[keyi])
		{
			prev++;
			Swap(&a[cur], &a[prev]);
			cur++;
		}
		else {
			cur++;
		}
	}
	Swap(&a[keyi], &a[prev]);
	keyi = prev;
	// [left, keyi-1] keyi [keyi+1, right]
	QuickSort_Point(a, left, keyi - 1);
	QuickSort_Point(a, keyi + 1, right);
}


int main()
{
	int a[] = { 9,5,1,7,3,6,8,4,2,0 };
	int len = sizeof(a) / sizeof(int);
	QuickSort_Point(a, 0, len-1);

	for (int i = 0; i < len; i++)
	{
		printf("%d ", a[i]);
	}
	return 0;
}